package com.wakala.employment.adapter;

import android.text.Html;

import com.wakala.employment.R;
import com.wakala.employment.adapter.base.broccoli.BroccoliRecyclerAdapter;
import com.wakala.employment.adapter.entity.JobInfoVo;
import com.wakala.employment.utils.DemoDataProvider;
import com.wakala.employment.utils.PlaceholderHelper;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;

import me.samlss.broccoli.Broccoli;

/**
 * @author xuexiang
 * @since 2019/4/7 下午12:06
 */
public class RecruitInfoListAdapter extends BroccoliRecyclerAdapter<JobInfoVo> {
    /**
     * 是否是加载占位
     */
    private boolean mIsAnim;

    public RecruitInfoListAdapter(boolean isAnim) {
        super(DemoDataProvider.getEmptyJobInfo());
        mIsAnim = isAnim;
    }


    @Override
    protected int getItemLayoutId(int viewType) {
        return R.layout.adapter_recruit_info_list_item;
    }

    /**
     * 绑定控件
     *
     * @param holder
     * @param model
     * @param position
     */
    @Override
    protected void onBindData(RecyclerViewHolder holder, JobInfoVo model, int position) {
        holder.text(R.id.tv_title, model.getTitle());
        holder.text(R.id.tv_tag,model.getJobCategoryName());
        holder.text(R.id.tv_summary, Html.fromHtml(model.getContent(),Html.FROM_HTML_MODE_COMPACT));
        holder.text(R.id.tv_praise, model.getPublishTime().substring(0, 16));
        holder.text(R.id.tv_comment, "评论");
        holder.text(R.id.tv_read, "阅读量 " + 0);
        holder.image(R.id.iv_image, model.getUser().getAvatar());
        //holder.text(R.id.tv_location, model.getJobUserAddress().getCity() + model.getJobUserAddress().getDistrict() + model.getJobUserAddress().getDetail());
    }

    /**
     * 绑定占位控件
     *
     * @param holder
     * @param broccoli
     */
    @Override
    protected void onBindBroccoli(RecyclerViewHolder holder, Broccoli broccoli) {
        if (mIsAnim) {
            broccoli.addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_user_name)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_tag)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_title)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_summary)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_praise)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_comment)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_read)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.iv_image)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.btn_link_boss)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tag_layout)));

        } else {
            broccoli.addPlaceholders(
                    holder.findView(R.id.tv_user_name),
                    holder.findView(R.id.tv_tag),
                    holder.findView(R.id.tv_title),
                    holder.findView(R.id.tv_summary),
                    holder.findView(R.id.tv_praise),
                    holder.findView(R.id.tv_comment),
                    holder.findView(R.id.tv_read),
                    holder.findView(R.id.iv_image),
                    holder.findView(R.id.btn_link_boss)
            );
        }
    }

}
